package com.feinno.urcs.group.http.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * Created by wuzhiguo on 15-5-15.
 */
public class StringHelper {

    public static boolean isNullOrEmpty(String str) {
        return str == null ? true : str.isEmpty();
    }

    public static String trimOneChar(String str, char ch) {
        String newstr = str;
        if (str != null && str.length() > 0) {
            int beginIndex = 0;
            int endIndex = str.length();
            if (str.charAt(0) == ch) {
                beginIndex++;
            }
            if (str.charAt(str.length() - 1) == ch) {
                endIndex--;
            }
            if (endIndex < beginIndex) {
                endIndex = beginIndex;
            }
            newstr = str.substring(beginIndex, endIndex);
        }

        return newstr;
    }

    public static String trimQuoteChar(String str) {
        return trimOneChar(str, '"');
    }

    public static String packOneChar(String str, char ch) {
        return String.format("%c%s%c", ch, str, ch);
    }

    public static String packQuoteChar(String str) {
        return packOneChar(str, '"');
    }

    public static String generateXmlDateFormatString(Date date) {
        // SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ssZ");
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
//        String dateString = dateFormat.format(date);
//        String timeString = timeFormat.format(date);
//        String dateTimeString = dateString + "T" + timeString + "Z";
        return date.toString();
//        return dateTimeString;
    }

    public static String generateUUIDString() {
        return UUID.randomUUID().toString();
    }
}
